package com.oa.ylms.apps.business.regulations.impl;

import java.util.List;

import com.oa.ylms.apps.business.regulations.IRegulationCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.regulations.IRegulationCategoryDao;
import com.oa.ylms.apps.entity.regulations.RegulationCategoryValue;

public class RegulationCategoryServiceImpl implements
		IRegulationCategoryService {

		private IRegulationCategoryDao categoryDao;
	    private RegulationCategoryValue regulationCategory;

		// Service method
	    
		public List<RegulationCategoryValue> queryAllCategory() throws Exception {
			return categoryDao.queryCategoryByStates(regulationCategory);
		}
		
		@Override
		public List<RegulationCategoryValue> queryCategoryByStates(Integer states) throws Exception {
			regulationCategory.setStates(states);
			return categoryDao.queryCategoryByStates(regulationCategory);
		}

		public RegulationCategoryValue queryCategoryById(int categoryId) throws Exception {
			regulationCategory.setCategoryId(categoryId);
			return categoryDao.queryCategoryById(regulationCategory);
		}
		
		public int addRegulationCategory( String categoryName,int states)throws Exception {
		     
			regulationCategory.setCategoryName(categoryName);
			regulationCategory.setStates(IDEDStates.ENABLE);
			return categoryDao.addNewsCategory(regulationCategory);
		}


		public boolean deleteRegulationCategory(int categoryId) throws Exception {
			regulationCategory=queryCategoryById(categoryId);
			regulationCategory.setStates(IDEDStates.DELETE);
			return categoryDao.editRegulationCategory(regulationCategory);
		}


		public boolean modifyRegulationCategory(int categoryId, String categoryName,
				int states) throws Exception {
			regulationCategory = queryCategoryById(categoryId);
			regulationCategory.setCategoryName(categoryName);
			regulationCategory.setStates(states);
			return categoryDao.editRegulationCategory(regulationCategory);
		}



		public boolean toDisable(int categoryId) throws Exception {
			regulationCategory = queryCategoryById(categoryId);
			regulationCategory.setStates(IDEDStates.DISABLE);
			return categoryDao.editRegulationCategory(regulationCategory);
		}

		public boolean toEnable(int categoryId) throws Exception {
			regulationCategory = queryCategoryById(categoryId);
			regulationCategory.setStates(IDEDStates.ENABLE);
			return categoryDao.editRegulationCategory(regulationCategory);
		}

		// Service property accessors
		
		public IRegulationCategoryDao getCategoryDao() {
			return categoryDao;
		}

		public void setCategoryDao(IRegulationCategoryDao categoryDao) {
			this.categoryDao = categoryDao;
		}

		public RegulationCategoryValue getRegulationCategory() {
			return regulationCategory;
		}

		public void setRegulationCategory(RegulationCategoryValue regulationCategory) {
			this.regulationCategory = regulationCategory;
		}




}
